class Element {
  constructor(tagName, props, children) {
    this.tagName = tagName
    this.props = props
    this.children = children

    if (props.key) {
      this.key = props.key
    }

    var count = 0
    children.forEach(child => {
      
    });    
  }
}

// 生成虚拟dom
function createElement(tagName, props, children) {
  return new Element(tagName, props, children)
}

// 虚拟dom渲染成真实dom
Element.prototype.render = function() {
  let el = document.createElement(this.tagName)
  let props = this.props

  for(let propName in props) {
    let propValue = props[propName]
    el.setAttribute(propName, propValue)
  }

  let children = this.children || []
  children.forEach(child => {
    child = (child instanceof Element)
      ? child.render()
      : document.createTextNode(child)
    
      el.appendChild(child)
  })

  return el
}

export {
  createElement
}